From 27a54379cf3c48ff63c02a4a9f023297bba60d45 Mon Sep 17 00:00:00 2001
From: Noel Kuntze <noel.kuntze@thermi.consulting>
Date: Mon, 12 Jul 2021 01:29:43 +0200
Subject: [PATCH 900/904] src: Patch for building with musl on openwrt (taken
 verbatim from openwrt package sources)

---
 .../kernel_netlink/kernel_netlink_ipsec.c     |  1 +
 .../kernel_netlink/kernel_netlink_net.c       |  2 +
 .../kernel_netlink/kernel_netlink_shared.c    |  2 +
 src/libstrongswan/library.h                   |  1 +
 src/libstrongswan/musl.h                      | 38 +++++++++++++++++++
 .../plugins/bliss/bliss_huffman.c             |  2 +
 6 files changed, 46 insertions(+)
 create mode 100644 src/libstrongswan/musl.h

--- a/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c
+++ b/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c
@@ -41,6 +41,7 @@
  */
 
 #define _GNU_SOURCE
+#include <musl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
--- a/src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c
+++ b/src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c
@@ -37,6 +37,8 @@
  * THE SOFTWARE.
  */
 
+#include "musl.h"
+
 #include <sys/socket.h>
 #include <sys/utsname.h>
 #include <linux/netlink.h>
--- a/src/libcharon/plugins/kernel_netlink/kernel_netlink_shared.c
+++ b/src/libcharon/plugins/kernel_netlink/kernel_netlink_shared.c
@@ -37,6 +37,8 @@
  * THE SOFTWARE.
  */
 
+#include "musl.h"
+
 #include <sys/socket.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
--- a/src/libstrongswan/library.h
+++ b/src/libstrongswan/library.h
@@ -121,6 +121,7 @@
 #include "utils/leak_detective.h"
 #include "plugins/plugin_loader.h"
 #include "settings/settings.h"
+#include "musl.h"
 
 typedef struct library_t library_t;
 
--- /dev/null
+++ b/src/libstrongswan/musl.h
@@ -0,0 +1,38 @@
+#include <sys/types.h>
+
+#define crypt x_crypt
+#define encrypt x_encrypt
+#include <unistd.h>
+
+#define fd_set x_fd_set
+#define ino_t x_ino_t
+#define off_t x_off_t
+#define loff_t x_loff_t
+#define dev_t x_dev_t
+#define mode_t x_mode_t
+#define uid_t x_uid_t
+#define gid_t x_gid_t
+#define uint64_t x_uint64_t
+#define u_int64_t x_u_int64_t
+#define int64_t x_int64_t
+#define nlink_t x_nlink_t
+#define timer_t x_timer_t
+#define blkcnt_t x_blkcnt_t
+
+#include <linux/types.h>
+
+#undef fd_set
+#undef ino_t
+#undef off_t
+#undef dev_t
+#undef mode_t
+#undef uid_t
+#undef gid_t
+#undef uint64_t
+#undef u_int64_t
+#undef int64_t
+#undef nlink_t
+#undef timer_t
+#undef blkcnt_t
+#undef crypt
+#undef encrypt
--- a/src/libstrongswan/plugins/bliss/bliss_huffman.c
+++ b/src/libstrongswan/plugins/bliss/bliss_huffman.c
@@ -18,6 +18,8 @@
 #include "bliss_param_set.h"
 
 #include <library.h>
+#undef fprintf
+#undef printf
 
 #include <stdio.h>
 #include <math.h>
